home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
050
/
bix02.arc
/
SCANTEST.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1986-08-04
|
2KB
|
80 lines
{using 'scan' for fast access to program text not in code space}
TITLE: 'Scan' example for reducing code size
Program extext;
type anystring=string[255];
var n,msglen:integer;
f:file;
p:^anystring;
{$I scan.pas}
procedure msgs;external 'extext.pas'; {text of this program in code seg}
function msg(n:integer):anystring;
{return lines from within external procedure 'msgs'}
var i,j,o:integer;
s:anystring;
begin
msg:='';
o:=ofs(msgs);
i:=0;
if n>=0 then
repeat
j:=scan(msglen-i,13,mem[cseg:ofs(msgs)+i]);
if n=0 then
begin
s[0]:=chr(j);
if j>0 then move(mem[cseg:ofs(msgs)+i],s[1],j);
msg:=s
end;
i:=i+j+2;
n:=n-1
until (n<0) or (i>msglen)
end;
function dmsg(n:integer):anystring;
{return lines from within varaiable p^ on heap}
var ss,i,j,o:integer;
s:anystring;
begin
dmsg:='';
ss:=seg(p^);
o:=ofs(p^);
i:=0;
if n>=0 then
repeat
j:=scan(msglen-i,13,mem[ss:ofs(p^)+i]);
if n=0 then
begin
s[0]:=chr(j);
if j>0 then move(mem[ss:ofs(p^)+i],s[1],j);
dmsg:=s
end;
i:=i+j+2;
n:=n-1
until (n<0) or (i>msglen)
end;
begin
{test for 'msg' routine, text in code space}
msglen:=scan(32000,26,mem[cseg:ofs(msgs)]); {initialize,search for ^Z}
repeat
write('Line number?....');readln(n);
writeln('Line #',n,'=<',msg(n),'>');
until n<0;
{test for 'dmsg', text not in code space}
assign(f,'extext.pas');
reset(f);
n:=filesize(f); {number of 128 byte blocks}
getmem(p,128*n); {second approach, read text into variable}
blockread(f,p^,n); {read in entire text file}
msglen:=scan(128*n,26,p^); {initialize, search for ^Z}
repeat
write('Line number?....');readln(n);
writeln('Line #',n,'=<',dmsg(n),'>');
until n<0;
end.